var processing = {
    id: "processingInfoTable",
    seItem: null,
    table: null,
    layerIndex: -1
};

processing.initColumn = function () {
    var columns = [
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '加工单位', field: 'processUnit', align: 'center', valign: 'middle', width: 120},
        {title: '操作', field: 'ids', align: 'center', valign: 'middle', width: 40,
            formatter: function (value, row, index) {
                return '<button type="button" class="btn" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" onclick="processing.deleteProject('+ row.id +')"><span class="glyphicon glyphicon-trash"></span></button>';
            }
        }
    ];
    return columns;
};

processing.search = function () {//查询加工单位列表
    processing.table.refresh();
};

processing.specialClose = function () {
    window.parent.getProcessInfo();
    processing.close();
};

processing.close = function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
};

processing.addUnit = function () {
    var index = layer.open({
        type: 2,
        title: '新增加工单位',
        area: ['50%', '50%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/add_process'
    });
    this.layerIndex = index;
};

processing.deleteProject = function (id) {
    if (confirm("确定要删除此加工单位？?")) {
        $.ajax({
            type: "POST",
            url: Feng.ctxPath + "/doctorLooked/delete_process",
            data: {
                "id":id
            },
            success: function (data) {
                Feng.success('操作成功!');
                window.processing.search();
            }
        });
    }
};

processing.preservationUnit = function () {
    if($("#processUnit").val() === "" || $("#processUnit").val() === undefined || $("#processUnit").val() === null){
        alert("加工单位名称不能为空!");
        return false;
    }
    $.ajax({
        type: "POST",
        url: Feng.ctxPath + "/doctorLooked/add_process_unit",
        data: {
            "processUnit":$("#processUnit").val()
        },
        success: function (data) {
            window.parent.processing.search();
            processing.close();
        }
    });
};

$(function () {
    var defaultColunms = processing.initColumn();
    var table = new BSTable(processing.id, "/doctorLooked/getProcessInfo" , defaultColunms);
    table.setPaginationType("client");
    processing.table = table.init();
    processing.search();
    $('#processingInfoTable').bootstrapTable('resetView', {height: $(window).height() - 40});
});